window.onload = function(){
    var vm = new Vue({
        el: '#main',
        data: {
            organCode: '',
            organCodeName:'',
            percent:"",
            zTree:null,
        },
        created: function () {
            this.initZtree();
        },
        methods: {
            chooseOrg(){
                $('#orgTree').modal({
                    relatedTarget: this,
                });
            },
            chooseBtnClick(){
                var node = this.zTree.getSelectedNodes()[0];
                this.organCodeName = node.branchName;
                this.organCode = node.branchId;
            },
            submit(){
                var data = {
                    organCode:this.organCode,
                    percent: this.percent,
                    startTime: $('#startTime').val(),
                    endTime: $('#endTime').val(),
                };
                axios({
                    method: 'post',
                    url: App.envUrl.backtrackUrl + 'check/distributePerson',
                    data: data,
                })
                .then((data) => {
                    if(data.data.code == 200){
                        history.back();
                    }else {
                        parent.showAlert(data.data.msg);
                    }
                })
                .catch((err) => {});
            },
            resetBtn(){
                this.organCode= '';
                this.organCodeName = '';
                this.percent="";
                $('#startTime').val('');
                $('#endTime').val('');
            },
            initZtree(){
                var setting = {
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "branchId",
                            pIdKey: "branchParentid"
                        },
                        key: {
                            name: "branchName"
                        }
                    },
                    view: {
                        dblClickExpand: false,
                        showLine: true,
                        showIcon: true,
                        selectedMulti: false
                    }
                };
                axios({
                    method: 'post',
                    url: App.envUrl.backtrackUrl + 'check/getBranchList',
                })
                .then((data) => {
                    if(data.data && data.data.data && data.data.data.length>0){
                        $.fn.zTree.init($("#menuTree"), setting, data.data.data);
                        vm.zTree = $.fn.zTree.getZTreeObj("menuTree");
                        vm.rMenu = $("#menuTree");
                    }
                })
                .catch((err) => {});
            }
        }
    });
}